package com.amoyt.project.controller.admin;


import com.amoyt.project.domain.dto.query.FundPageQuery;
import com.amoyt.project.domain.res.Result;
import com.amoyt.project.exception.BusinessException;
import com.amoyt.project.exception.enums.BusinessExceptionEnum;
import com.amoyt.project.service.admin.FundService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 资金投入申请主表（存储资金申请信息） 前端控制器
 * </p>
 *
 * @author AmoyT
 * @since 2025-08-24
 */
@RestController
@RequestMapping("/admin/fundApproval")
@Tag(name = "资金投入申请接口",description = "资金投入申请接口")
public class FundController {

    @Autowired
    private FundService fundService;

    /**
     * 资金投入申请列表
     * @param query
     * @return
     */
    @GetMapping("/list-all")
    @Operation(summary = "下级资金投入申请列表",method = "GET")
    @Parameter(name = "token",description = "访问令牌",required = true,in = ParameterIn.HEADER)
    @PreAuthorize("hasAnyRole('super_admin','prov_admin','city_admin','region_admin')")
    public Result listAll(FundPageQuery query) {
        if (query == null || query.getPage() == null || query.getPageSize() == null){
            throw new BusinessException(BusinessExceptionEnum.PARAM_ERROR);
        }
        return fundService.listAll(query);
    }

    /**
     * 个人资金投入申请列表
     * @param query
     * @return
     */
    @GetMapping("/list-own")
    @Operation(summary = "资金投入个人申请列表",method = "GET")
    @Parameter(name = "token",description = "访问令牌",required = true,in = ParameterIn.HEADER)
    @PreAuthorize("hasAnyRole('super_admin','prov_admin','city_admin','region_admin')")
    public Result listOwn(FundPageQuery query) {
        if (query == null || query.getPage() == null || query.getPageSize() == null){
            throw new BusinessException(BusinessExceptionEnum.PARAM_ERROR);
        }
        return fundService.listOwn(query);
    }

}

